import java.util.*; class demo { public static void main(String args[]) { HashSet setA=new HashSet(); setA.add("C"); setA.add("C++"); setA.add("Java"); setA.add("MySQL"); setA.add("HTML"); HashSet setB=new HashSet(); setB.add("Python"); setB.add("C"); setB.add("Java"); System.out.println("SetA is "+setA); System.out.println("SetB is "+setB); setA.addAll(setB); System.out.println("Union SetA and SetB is "+setA); } }
SetA is [Java, C++, C, MySQL, HTML] SetB is [Java, C, Python] Union SetA and SetB is [Java, C++, C, MySQL, HTML, Python]
import java.util.*; class demo { public static void main(String args[]) { HashSet setA=new HashSet(); setA.add("C"); setA.add("C++"); setA.add("Java"); setA.add("MySQL"); setA.add("HTML"); HashSet setB=new HashSet(); setB.add("Python"); setB.add("C"); setB.add("Java"); System.out.println("SetA is "+setA); System.out.println("SetB is "+setB); setA. retainAll(setB); System.out.println("Union SetA and SetB is "+setA); } }
SetA is [Java, C++, C, MySQL, HTML] SetB is [Java, C, Python] Union SetA and SetB is [Java, C]
import java.util.*; class demo { public static void main(String args[]) { HashSet setA=new HashSet(); setA.add("C"); setA.add("C++"); setA.add("Java"); setA.add("MySQL"); setA.add("HTML"); HashSet setB=new HashSet(); setB.add("Python"); setB.add("C"); setB.add("Java"); System.out.println("SetA is "+setA); System.out.println("SetB is "+setB); setA.removeAll(setB); System.out.println("Union SetA and SetB is "+setA); } }
SetA is [Java, C++, C, MySQL, HTML] SetB is [Java, C, Python] Union SetA and SetB is [C++, MySQL, HTML]